package lch.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lch.dao.CheckItemDao;
import lch.dao.CheckPermissionDao;
import lch.entity.PageResult;
import lch.entity.QueryPageBean;
import lch.entity.Result;
import lch.pojo.CheckItem;
import lch.pojo.Permission;
import lch.pojo.Role;
import lch.service.CheckItemService;
import lch.service.CheckPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lch
 * @date 2019-12-19 20:31
 */
@Service(interfaceClass = CheckPermissionService.class)
@Transactional
public class CheckPermissionServiceImpl implements CheckPermissionService {

    @Autowired
    private CheckPermissionDao checkPermissionDao;

    @Override
    public void add(Permission permission) {
        checkPermissionDao.add(permission);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Permission> page = checkPermissionDao.selectByCondition(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void delete(Integer id) {
        //        long count = checkPermissionDao.findCountByPermissionId(id);
        //        if (count > 0) {
        //            new RuntimeException();
        //        }
        checkPermissionDao.deleteById(id);
    }

    @Override
    public Permission findById(Integer id) {
        return checkPermissionDao.findById(id);
    }

    @Override
    public void edit(Permission permission) {
        checkPermissionDao.edit(permission);
    }

    @Override
    public List<Permission> findAll() {
        return checkPermissionDao.findAll();
    }
}